var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), a = require("../../../@babel/runtime/helpers/defineProperty"), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), i = getApp(), s = null;

Component({
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        U_tabcontrol: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        index: {
            type: null
        },
        bottomShowBol: {
            type: null
        },
        plugin_active: String
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        language: "",
        active: "0",
        class_id: "0",
        list: [],
        categories: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        pageSize: 12,
        noNotice: !1,
        allLoaded: !1,
        playInd: null,
        postStart: !1,
        sliderShow: !1
    },
    lifetimes: {
        attached: function() {
            var t = wx.getStorageSync("langIndex");
            this.setData({
                language: t.en
            }), s = wx.createInnerAudioContext(), this.init();
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        }), 1 == this.data.datas.get_style || 3 == this.data.datas.get_style ? (this.initData(), 
        this.getNetData(this.data.datas)) : this.setData({
            isLoadMore: !1,
            allLoaded: !0
        });
    },
    pageLifetimes: {
        show: function() {
            s = wx.createInnerAudioContext(), this.init();
        },
        hide: function() {
            s.stop(), s.destroy();
        },
        resize: function() {}
    },
    observers: {
        bottomShowBol: function(t) {
            this.data.bottomShowBolIndex == this.data.index && this.getMoreData();
        }
    },
    methods: {
        tapMethod: function(t) {
            t.currentTarget.dataset.item.playStatus ? this.pause(t) : this.startPlayOrPause(t);
        },
        checkNoticeVideo: function(t) {
            return new Promise(function(a, e) {
                i._getNetWork({
                    url: i.getNetAddresss("plugin.article-pay.api.index.paid"),
                    data: {
                        article_id: t
                    },
                    success: function(t) {
                        var e = t.data;
                        a(e.result);
                    },
                    fail: function(t) {
                        e(t);
                    }
                });
            });
        },
        startPlayOrPause: function(i) {
            var d = this;
            return e(t.default.mark(function e() {
                var l, o, r, n, c;
                return t.default.wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        if (1 != (l = i.currentTarget.dataset.item).is_pay && !l.has_one_article_pay) {
                            t.next = 8;
                            break;
                        }
                        return t.next = 4, d.checkNoticeVideo(l.id);

                      case 4:
                        if (0 != t.sent) {
                            t.next = 8;
                            break;
                        }
                        return wx.navigateTo({
                            url: "/packageD/article/articleList/articleList?article_id=" + l.id
                        }), t.abrupt("return");

                      case 8:
                        return t.next = 10, d.checkPrivilege(l.id);

                      case 10:
                        if (0 != (o = t.sent).result) {
                            t.next = 16;
                            break;
                        }
                        return wx.showToast({
                            title: o.msg,
                            icon: "none",
                            duration: 1e3
                        }), t.abrupt("return");

                      case 16:
                        for (r = i.currentTarget.dataset.i, n = 2 == d.data.datas.get_style ? d.data.datas.list : d.data.list, 
                        d.data.sliderShow || d.setData({
                            sliderShow: !0
                        }), c = 0; c < n.length; c++) n[c].playStatus = !1;
                        n[r].playStatus = !0, d.data.playInd != r && (s.stop(), d.data.postStart = !1), 
                        d.setData({
                            playInd: r
                        }), 2 == d.data.datas.get_style ? d.setData(a({}, "datas.list", d.data.datas.list)) : d.setData({
                            list: d.data.list
                        }), s.src = encodeURI(l.audio_link), s.play();

                      case 26:
                      case "end":
                        return t.stop();
                    }
                }, e);
            }))();
        },
        checkPrivilege: function(t) {
            return new Promise(function(a, e) {
                var s = i.getNetAddresss("plugin.article.api.article.get-article");
                i._getNetWork({
                    url: s,
                    data: {
                        article_id: t
                    },
                    success: function(t) {
                        var e = t.data;
                        e.result, a(e);
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            });
        },
        pause: function(t) {
            var e = t.currentTarget.dataset.i;
            (2 == this.data.datas.get_style ? this.data.datas.list : this.data.list)[e].playStatus = !1, 
            this.data.postStart = !0, 2 == this.data.datas.get_style ? this.setData(a({}, "datas.list", this.data.datas.list)) : this.setData({
                list: this.data.list
            }), s.pause();
        },
        tapClose: function() {
            this.setData({
                sliderShow: !1
            });
        },
        sildein: function(t) {
            var e = t.detail.value / 100, i = this.data.audio_length * e;
            2 == this.data.datas.get_style ? (this.data.datas.list[this.data.playInd].playStatus = !1, 
            this.setData(a({}, "datas.list", this.data.datas.list))) : (this.data.list[this.data.playInd].playStatus = !1, 
            this.setData({
                list: this.data.list
            })), s.seek(i), s.play();
        },
        changeSilde: function(t) {
            var e = t.detail, i = this.data.audio_length * (e / 100);
            2 == this.data.datas.get_style ? (this.data.datas.list[this.data.playInd].playStatus = !0, 
            this.setData(a({}, "datas.list", this.data.datas.list))) : (this.data.list[this.data.playInd].playStatus = !0, 
            this.setData({
                list: this.data.list
            })), s.seek(i), s.play();
        },
        init: function() {
            var t = this;
            s.onCanplay(function() {}), s.onPlay(function() {
                t.startPostMethod();
            }), s.onTimeUpdate(function() {
                setTimeout(function() {
                    var a = s.currentTime / s.duration * 100, e = parseInt(a);
                    t.setData({
                        valueSlmin: e,
                        audio_length: s.duration
                    });
                }, 500);
            }), s.onEnded(function(e) {
                2 == t.data.datas.get_style ? t.data.datas.list[t.data.playInd].playStatus = !1 : t.data.list[t.data.playInd].playStatus = !1, 
                2 == t.data.datas.get_style ? t.setData(a({}, "datas.list", t.data.datas.list)) : t.setData({
                    list: t.data.list
                }), t.data.postStart = !1;
            }), s.onError(function(t) {});
        },
        startPostMethod: function() {
            var t = this;
            if (0 == this.data.postStart) {
                var e = i.getNetAddresss("plugin.article.api.article.clickAudioViews"), s = {
                    article_id: ""
                };
                2 == this.data.datas.get_style ? s.article_id = this.data.datas.list[this.data.playInd].id : s.article_id = this.data.list[this.data.playInd].id, 
                i._getNetWork({
                    url: e,
                    data: s,
                    success: function(e) {
                        var i = e.data;
                        1 == i.result && (2 == t.data.datas.get_style ? (t.data.datas.list[t.data.playInd].virtual_audio_views = i.data.virtual_audio_views, 
                        t.setData(a({}, "datas.list", t.data.datas.list))) : (t.data.list[t.data.playInd].virtual_audio_views = i.data.virtual_audio_views, 
                        t.setData({
                            list: t.data.list
                        })));
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            } else console.log("暂停过 postStart = true");
        },
        initData: function() {
            s && s.stop(), this.setData({
                page: 1,
                total_page: 0,
                isLoadMore: !0,
                list: [],
                sliderShow: !1
            });
        },
        getNetData: function(t) {
            var a = this, e = this;
            if (t) return this.setData({
                noNotice: !1,
                total_page: t.list.last_page,
                pageSize: t.list.per_page,
                isLoadMore: !0
            }), e.data.total_page <= 1 && this.setData({
                isLoadMore: !1,
                allLoaded: !0
            }), t.list.data && t.list.data.length > this.data.datas.get_number && (t.list.data.splice(this.data.datas.get_number, t.list.data.length - this.data.datas.get_number), 
            this.setData({
                isLoadMore: !1,
                allLoaded: !0
            })), this.setData({
                list: t.list.data
            }), void (t.cate && (this.setData({
                categories: t.cate,
                class_id: t.cate[0] && 1 != this.data.datas.get_style ? t.cate[0].id : "0",
                active: t.cate[0] && 1 != this.data.datas.get_style ? t.cate[0].id : "0"
            }), t.cate.length <= 0 && this.setData({
                noNotice: !0
            })));
            var s = {
                category_id: this.data.class_id,
                page: 1,
                pageSize: 12,
                show_audio: this.data.datas.show_audio,
                is_decorate: !0
            }, d = i.getNetAddresss("plugin.article.api.article.get-articles");
            i._getNetWork({
                url: d,
                data: s,
                success: function(t) {
                    var i = t.data;
                    1 == i.result ? (e.setData({
                        noNotice: !1,
                        total_page: i.data.articles.last_page,
                        pageSize: i.data.articles.per_page,
                        isLoadMore: !0
                    }), e.data.total_page <= 1 && e.setData({
                        isLoadMore: !1,
                        allLoaded: !0
                    }), i.data.categories.length <= 0 && e.setData({
                        noNotice: !0
                    }), i.data.articles.data.length > a.data.datas.get_number && (i.data.articles.data.splice(a.data.datas.get_number, i.data.articles.data.length - a.data.datas.get_number), 
                    a.setData({
                        isLoadMore: !1,
                        allLoaded: !0
                    })), e.setData({
                        list: i.data.articles.data
                    })) : e.setData({
                        noNotice: !0
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        toNoticeInfo: function(t) {
            var a = t.currentTarget.dataset.item;
            console.log(a), !a.has_one_article_pay || a.has_one_record ? 1 == a.type ? wx.navigateTo({
                url: "/packageA/member/course/VoiceDetail/VoiceDetail?article_id=" + a.id
            }) : wx.navigateTo({
                url: "/packageA/member/article/articleContent/articleContent?article_id=" + a.id
            }) : wx.navigateTo({
                url: "/packageD/article/articleList/articleList?article_id=" + a.id
            });
        },
        onClick: function(t) {
            var a = t.detail.index;
            console.log(this.data.categories, "188"), this.initData(), 0 === a ? 1 == this.data.datas.get_style ? this.setData({
                class_id: "0",
                active: "0"
            }) : this.setData({
                class_id: this.data.categories[a].id,
                active: String(this.data.categories[a].id)
            }) : this.setData({
                class_id: 1 == this.data.datas.get_style ? this.data.categories[a - 1].id : this.data.categories[a].id,
                active: 1 == this.data.datas.get_style ? String(this.data.categories[a - 1].id) : String(this.data.categories[a].id)
            }), this.getNetData();
        },
        getMoreData: function() {
            var t = this, a = this;
            if (a.setData({
                isLoadMore: !1
            }), this.data.page >= this.data.total_page || this.data.list.length > this.data.datas.get_number) a.setData({
                isLoadMore: !1
            }); else {
                a.setData({
                    page: this.data.page + 1
                });
                var e = {
                    category_id: this.data.class_id,
                    page: this.data.page,
                    pageSize: this.data.pageSize,
                    show_audio: this.data.datas.show_audio,
                    is_decorate: !0
                }, s = i.getNetAddresss("plugin.article.api.article.get-articles");
                i._getNetWork({
                    url: s,
                    data: e,
                    success: function(e) {
                        var i = e.data;
                        if (1 == i.result) {
                            a.setData({
                                total_page: i.data.articles.last_page
                            }), t.data.page < t.data.total_page ? a.setData({
                                isLoadMore: !0
                            }) : a.setData({
                                allLoaded: !0
                            });
                            var s = a.data.list.concat(i.data.articles.data);
                            s.length > t.data.datas.get_number && (s.splice(t.data.datas.get_number, s.length - t.data.datas.get_number), 
                            a.setData({
                                isLoadMore: !1,
                                allLoaded: !0
                            })), a.triggerEvent("setLoadMore", {
                                isLoadMore: a.data.isLoadMore
                            }), a.setData({
                                list: s
                            });
                        } else a.setData({
                            page: a.data.page - 1,
                            isLoadMore: !1,
                            allLoaded: !0
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        }
    }
});